package com.itheima.notify.listener;

import com.itheima.common.constants.RocketMQConstants;
import com.itheima.common.entity.NotifyMessage;
import com.itheima.notify.service.NotifyMessageService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.itheima.common.constants.RocketMQConstants.CONSUMER.USER_APPLY_CONSUMER;
import static com.itheima.common.constants.RocketMQConstants.TAGS.USER_APPLY_TAGS;
import static com.itheima.common.constants.RocketMQConstants.TOPIC.USER_TOPIC_NAME;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = USER_APPLY_CONSUMER,
        topic = USER_TOPIC_NAME,
        selectorExpression = USER_APPLY_TAGS
)
public class NotifyMessageListener implements RocketMQListener<NotifyMessage> {


    @Autowired
    private NotifyMessageService notifyMessageService;


    @Override
    public void onMessage(NotifyMessage message) {
        log.info("【推送消息微服务】-员工加入企业申请：{}", message);
        try {
            notifyMessageService.sendPushMsgByAlias(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
